package com.ruoyi.project.wenyanwen.search.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wenyanwen.search.domain.HotSearch;
import com.ruoyi.project.wenyanwen.search.service.IHotSearchService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 热搜列表Controller
 * 
 * @author shixiangwen
 * @date 2020-08-24
 */
@Controller
@RequestMapping("/wenyanwen/search")
public class HotSearchController extends BaseController
{
    private String prefix = "wenyanwen/search";

    @Autowired
    private IHotSearchService hotSearchService;

    @RequiresPermissions("wenyanwen:search:view")
    @GetMapping()
    public String search()
    {
        return prefix + "/search";
    }

    /**
     * 查询热搜列表列表
     */
    @RequiresPermissions("wenyanwen:search:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HotSearch hotSearch)
    {
        startPage();
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        return getDataTable(list);
    }

    /**
     * 导出热搜列表列表
     */
    @RequiresPermissions("wenyanwen:search:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HotSearch hotSearch)
    {
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        ExcelUtil<HotSearch> util = new ExcelUtil<HotSearch>(HotSearch.class);
        return util.exportExcel(list, "search");
    }

    /**
     * 新增热搜列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存热搜列表
     */
    @RequiresPermissions("wenyanwen:search:add")
    @Log(title = "热搜列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HotSearch hotSearch)
    {
        return toAjax(hotSearchService.insertHotSearch(hotSearch));
    }

    /**
     * 修改热搜列表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HotSearch hotSearch = hotSearchService.selectHotSearchById(id);
        mmap.put("hotSearch", hotSearch);
        return prefix + "/edit";
    }

    /**
     * 修改保存热搜列表
     */
    @RequiresPermissions("wenyanwen:search:edit")
    @Log(title = "热搜列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HotSearch hotSearch)
    {
        return toAjax(hotSearchService.updateHotSearch(hotSearch));
    }

    /**
     * 删除热搜列表
     */
    @RequiresPermissions("wenyanwen:search:remove")
    @Log(title = "热搜列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hotSearchService.deleteHotSearchByIds(ids));
    }
}
